package com.ruoyi.purchase.controller;

import com.ruoyi.purchase.domain.FirmAccount;
import com.ruoyi.purchase.service.IFirmAccountService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结算账户Controller
 * 
 * @author ruoyi
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/account")
public class FirmAccountController extends BaseController
{
    @Autowired
    private IFirmAccountService firmAccountService;

    /**
     * 查询结算账户列表
     */
    @RequiresPermissions("purchase:account:list")
    @GetMapping("/list")
    public TableDataInfo list(FirmAccount firmAccount)
    {
        startPage();
        List<FirmAccount> list = firmAccountService.selectFirmAccountList(firmAccount);
        return getDataTable(list);
    }

    /**
     * 导出结算账户列表
     */
    @RequiresPermissions("purchase:account:export")
    @Log(title = "结算账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirmAccount firmAccount)
    {
        List<FirmAccount> list = firmAccountService.selectFirmAccountList(firmAccount);
        ExcelUtil<FirmAccount> util = new ExcelUtil<FirmAccount>(FirmAccount.class);
        util.exportExcel(response, list, "结算账户数据");
    }

    /**
     * 获取结算账户详细信息
     */
    @RequiresPermissions("purchase:account:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(firmAccountService.selectFirmAccountById(id));
    }

    /**
     * 新增结算账户
     */
    @RequiresPermissions("purchase:account:add")
    @Log(title = "结算账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirmAccount firmAccount)
    {
        return toAjax(firmAccountService.insertFirmAccount(firmAccount));
    }

    /**
     * 修改结算账户
     */
    @RequiresPermissions("purchase:account:edit")
    @Log(title = "结算账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirmAccount firmAccount)
    {
        return toAjax(firmAccountService.updateFirmAccount(firmAccount));
    }

    /**
     * 删除结算账户
     */
    @RequiresPermissions("purchase:account:remove")
    @Log(title = "结算账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(firmAccountService.deleteFirmAccountByIds(ids));
    }
}
